<?php
/**
 * 微博后台管理项目 媒体表数据层

 */
define("CACHE_ALBUM_TO_MBLOG","album_to_mblog_");
class db_album_to_mblog extends db_base
{
	var $table_name  ="album_to_mblog";
	
	

	
	/**
	 * 根据D_ID取数据
	 * @param $d_id
	 */
	function get_album_status_count_by_album_id($album_id)
	{
		$album_id = intval($album_id);
		$key = CACHE_album_to_mblog . "-get_album_status_count_by_album_id-{$album_id}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where = " album_id = '{$album_id}' and status =1  ";
			$content = $this->get_listcount($this->table_name,$where);
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_10);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content;
	}
	
	
	
	/**
	 * 根据D_ID取数据
	 * @param $d_id
	 */
	function get_album_status_list_by_album_id($album_id,$p=1,$pcount=20,$show_order=0,$field="")
	{
		$album_id = intval($album_id);
		$p = intval($p);
		$pcount = intval($pcount);
		$show_order = intval($show_order);
		
		$key = CACHE_album_to_mblog . "-get_album_status_list_by_album_id-{$album_id}-{$p}-{$pcount}-{$show_order}-{$field}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where = " album_id = '{$album_id}' and status =1  ";
			if($show_order == 0)
			{
				$order = "update_time desc";
			}
			else
			{
				$order = "update_time ";
			}
			$content = $this->get_alllist($this->table_name,$p,$pcount,$order ,$where,"",$field);
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_10);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content;
	}
	
		/**
	 * 根据D_ID取数据
	 * @param $d_id
	 */
	function get_album_status_list_by_album_id_nocache($album_id,$p=1,$pcount=20)
	{
		$album_id = intval($album_id);
		$p = intval($p);
		$pcount = intval($pcount);
		
		$where = " album_id = '{$album_id}' and status =1  ";
		$content = $this->get_alllist($this->table_name,$p,$pcount,"update_time " ,$where);

		return $content;
	}
	
	
	

	function insert_album_to_mblog($album_id,$mblog_id,$create_time)
	{
		$ary["status"] = 1;
		if($create_time)
		{
			$ary["update_time"] = $create_time;
		}
		else
		{
			$ary["update_time"] = Date::get_date_time();
		}
	
		$ary["album_id"] = $album_id;
		$ary["mblog_id"] = $mblog_id;
		
		$ret = $this->insert($this->table_name, $ary ,"",true);
		
		$mc = mem_cache::get_instance();
		$key[] = CACHE_album_to_mblog . "-get_album_status_count_by_album_id-{$album_id}";
		$key[] = CACHE_album_to_mblog . "-get_album_status_list_by_album_id-{$album_id}-1-16-0-";
		$key[] = CACHE_album_to_mblog . "-get_album_status_list_by_album_id-{$album_id}-1-16-1-";
		$cache = $mc->delete_ary($key);
		
		
		return $ret;
		
	}
	
	function update_album_to_mblog($album_id,$mblog_id,$status)
	{
		$album_id = intval($album_id);
		$mblog_id = intval($mblog_id);
		
		if(strlen($status)>0)$ary["status"] = $status;
		
		$ary["update_time"] = Date::get_date_time();
		
		$where = " album_id = $album_id and  mblog_id = $mblog_id";
		
		$res = $this->update($this->table_name,$ary,$where);
		
		$mc = mem_cache::get_instance();
		$key[] = CACHE_album_to_mblog . "-get_album_status_count_by_album_id-{$album_id}";
		$key[] = CACHE_album_to_mblog . "-get_album_status_list_by_album_id-{$album_id}-1-16-0-";
		$key[] = CACHE_album_to_mblog . "-get_album_status_list_by_album_id-{$album_id}-1-16-1-";
		$cache = $mc->delete_ary($key);
		return $res;
	}
	
	
}
